package com.xquant.pricing.pricingConfig.controller;

import com.xquant.common.security.utils.SecurityUtils;
import com.xquant.pricing.calc.entity.ResponseVo;
import com.xquant.pricing.pricingConfig.service.ComboBoxService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

@RestController
@RequestMapping("comboBox")
public class ComboBoxController {
    @Autowired
    private ComboBoxService comboBoxService;


    /**
     * 查询定价配置下拉列表供接口使用
     */


    @RequestMapping(value = "/queryPriceCfg.action")
    @ResponseBody
    public Object queryPriceCfg(@RequestBody Map<String, Object> params) {
        return ResponseVo.success(doQueryPriceCfg(params));
    }

    /**
     * newCloud 查询定价配置下拉列表
     */
    @RequestMapping(value = "/queryPriceCfg4Local.action")
    @ResponseBody
    public Object queryPriceCfg4Local(@RequestParam Map params) {

        List list = doQueryPriceCfg(params);
        return ResponseVo.success(list);
    }

    public List doQueryPriceCfg(Map params) {
        params.put("userId", SecurityUtils.getUserId());
        List<Map<String, Object>> list = comboBoxService.queryPriceCfg(params);
        return list;
    }

    /**
     * 查询贴现率&融资率曲线下拉列表
     */
    @RequestMapping(value = "/queryIrcurve.action")
    @ResponseBody
    public Object queryIrcurve(HttpServletRequest request) {
        Map<String, Object> params = new WeakHashMap<>();
        params.put("condition", request.getParameter("query"));
        if (StringUtils.isBlank(request.getParameter("query"))) {
            params.put("condition", request.getParameter("condition"));
        }

        List<Map<String, Object>> list = comboBoxService.queryTirCurve(params);

        return ResponseVo.success(list);
    }

    /**
     * 查询贴现率&融资率曲线下拉列表
     */


    @RequestMapping(value = "/queryIrcurveFilter.action")
    @ResponseBody
    public Object queryIrcurveFilter(HttpServletRequest request) {
        Map<String, Object> params = new WeakHashMap<>();
        params.put("condition", request.getParameter("query"));
        if (StringUtils.isBlank(request.getParameter("query"))) {
            params.put("condition", request.getParameter("condition"));
        }
        params.put("pipeId", "");
        params.put("userId",SecurityUtils.getUserId());
        List<Map<String, Object>> list = comboBoxService.queryTirCurve(params);

        return ResponseVo.success(list);
    }

    /**
     * 查询波动率曲线下拉列表
     */
    @RequestMapping(value = "/queryVolsurface.action")
    @ResponseBody
    public Object queryVolSurface(HttpServletRequest request) {
        Map<String, Object> params = new WeakHashMap<>();
        params.put("condition", request.getParameter("query"));
        if (StringUtils.isBlank(request.getParameter("query"))) {
            params.put("condition", request.getParameter("condition"));
        }
        params.put("userId",SecurityUtils.getUserId());
        List<Map<String, Object>> list = comboBoxService.queryVolSurface(params);

        return ResponseVo.success(list);
    }

    /**
     * 查询红利率曲线下拉列表
     */
    @RequestMapping(value = "/queryDivyield.action")
    @ResponseBody
    public Object queryDivYield(HttpServletRequest request) {
        Map<String, Object> params = new WeakHashMap<>();
        params.put("condition", request.getParameter("query"));
        if (StringUtils.isBlank(request.getParameter("query"))) {
            params.put("condition", request.getParameter("condition"));
        }

        List<Map<String, Object>> list = comboBoxService.queryDivYield(params);

        return ResponseVo.success(list);
    }

    /**
     * 查询违约率曲线下拉列表
     */
    @RequestMapping(value = "/queryDefCurve.action")
    @ResponseBody
    public Object queryDefCurve(HttpServletRequest request) {
        Map<String, Object> params = new WeakHashMap<>();
        params.put("condition", request.getParameter("query"));
        if (StringUtils.isBlank(request.getParameter("query"))) {
            params.put("condition", request.getParameter("condition"));
        }

        List<Map<String, Object>> list = comboBoxService.queryDefCurve(params);

        return ResponseVo.success(list);
    }
}
